/**
 * @param {number[]} nums
 * @param {number} start
 * @param {number} goal
 * @return {number}
 */
 var minimumOperations = function(nums, start, goal) {
  let q = [start]
  let cnt = 0
  let memo = new Set()
  while(q.length) {
    let s = new Set()
    for(let i = 0, len = q.length; i<len; i++){
      let cur = q.shift()
      if(cur === goal) return cnt
      if(cur < 0 || cur > 1000) continue
      for(let x of nums){
        s.add(cur+x)
        s.add(cur-x)
        s.add(cur^x)
      }
    }
    for(let x of s){
      if(!memo.has(x)){
        q.push(x)
      }
      memo.add(x)
    }
    cnt++
  }
  return -1
};